<?php
class Admin_VctInfoController extends Apps_Controller_Action_Admin {
	public function indexAction() {
		$rq   = $this->_request;

    	$tbVctInfo = new M_DbTable_VctInfo();
        $vctInfo = $tbVctInfo->getVctInfo()->query()->fetch();

        $form = new Admin_Form_AddVctInfo();
        if($rq->isPost()) {
            if($form->isValid($rq->getParams())) {
                $data = $form->getValues();
                $data['password_email_send_to_friend'] = rand(10000, 99999).'vct'.$form->getValue('password_email_send_to_friend').'@760211';
                if(!$vctInfo) {
                    $r = $tbVctInfo->safelyInsert($data);
                } else {
                    $r = $tbVctInfo->safelyUpdate($data, array('id =?' => $vctInfo['id']));
                }

                $this->_flashMessenger->addMessage(
                	$r
                    ? self::$msgAddSuccess
                    : self::$msgAddFailed);
                return $this->goToActionIndex();
            }
        } else {
            if($vctInfo) {
                $form->populate($vctInfo);
            }
        }

        $this->view->form = $form;
	}
}
